import { reactive, ref } from 'vue'
import { Requestattention, delectAttention } from '@/api/syxelement.js'
import { ElMessage } from 'element-plus'

let userid = null
const data = reactive({
  list: []
})

export default function getAttentionFunAll () {
  function requextAtt () {
    if (window.localStorage.getItem('user')) {
      userid = JSON.parse(window.localStorage.getItem('user')).data.results[0].id
      Requestattention({ id: userid }).then(res => {
        data.list = res.data.results
        console.log(res.data.results)
        if (data.list.length === 0) {
          ElMessage({
            showClose: true,
            message: '没有关注的人',
            type: 'warning'
          })
        }
      })
    }
  }
  function clickBtn (id) {
    delectAttention({
      id: id
    }).then(res => {
      if (res.data.message === true) {
        ElMessage.success({
          message: '已经取消关注',
          type: 'success'
        })
        console.log('删除成功')
        requextAtt()
      }
    })
  }
  return {
    userid,
    data,
    requextAtt,
    clickBtn
  }
}
